import request from '@/utils/request.js';
import { baseUrl } from "@/utils/util.js";
/**
 * 上传文件
 * @param {File} file - 要上传的文件
 * @returns {Promise} 返回上传结果
 */
export const uploadFile = (file) => {
  return new Promise((resolve, reject) => {
    uni.uploadFile({
      url: `${baseUrl}/app-api/infra/file/upload`,
      filePath: file,
      name: 'file',
      header: {
        platform: "uniapp",
        "tenant-id": "1",
        "Authorization": "Bearer " + uni.getStorageSync("token"),
      },
      success: (res) => {
        if (res.statusCode === 200) {
          const data = JSON.parse(res.data);
          if (data.code === 0) {
            resolve(data.data);
          } else {
            reject(data.msg || '上传失败');
          }
        } else {
          reject('上传失败');
        }
      },
      fail: (err) => {
        reject(err || '上传失败');
      }
    });
  });
}; 